﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using MuaChungDAO;
using MuaChungDAO;

namespace DoAnMuaChung.Deal
{
    public partial class NestedDeal : System.Web.UI.MasterPage
    {
        public string tenDeal = "";
        public string moTa = "";
        public int donGia = 0;
        public int tietKiem = 0;
        public int giaSauTietKiem = 0;

        public int soNguoiMua = 0;

        public string diemNoiBat = "";
        public string dieuKien = "";
        

        protected void Page_Load(object sender, EventArgs e)
        {
            /**
             * Do nạp theo ID chỉ cho ra 1 Deal duy nhất
             * => không dùng repeater hay datalist rồi databind() ra ngoài
             * mà tạo các thuộc tính tương ứng rồi đẩy trực tiếp ra
             */

            string dealId = Request.QueryString["DealID"];            
            System.Data.DataRow dealRow = DealHandler.napTheoID(dealId).Rows[0];

            // gán cho các thuộc tính để đẩy ra ngoài
            tenDeal = dealRow["TenDeal"].ToString();
            moTa = dealRow["MoTa"].ToString();

            donGia = (int)dealRow["DonGia"];
            tietKiem = (int)dealRow["TietKiem"];
            giaSauTietKiem = (int)(Math.Round((double)(donGia * (1 - (double)tietKiem / 100) / 1000), 3) * 1000);

            diemNoiBat = dealRow["DiemNoiBat"].ToString();
            dieuKien = dealRow["DieuKien"].ToString();

            // load hình ảnh
            dataList_HinhAnh.DataSource = HinhAnhDealHandler.napTheoID(dealId);
            dataList_HinhAnh.DataBind();

            // đếm số người mua (chỉ đếm chưa xác nhận và đã xác nhận, không đếm đã hủy)            
            soNguoiMua = DonHangHandler.demSoNguoiMuaCuaDeal(dealId);



        }
    }
}